<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Test</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <style>
    .page {
      height: 500px;
    }
    .page img {
      max-width: 100%;
      margin-top: 50px;
    }
    .page-1 {
      background: rgba(255, 0, 0, 0.5);
    }
    .page-2 {
      /* height: 200px; */
      background: rgba(0, 0, 255, 0.5);
    }
    .page-3 {
      /* height: 200px; */
      background: rgba(255, 255, 0, 0.5);
    }
    .page-4 {
      background: rgba(255, 0, 0, 0.5);
    }
    .page-5 {
      /* height: 200px; */
      background: rgba(0, 0, 255, 0.5);
    }
  </style>
  <script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.7/dist/html2canvas.min.js"></script>
</head>
<body>
  <button id="print-btn" class="btn btn-success m-5">生成PDF</button>

  <div id="page" style="width: 595.28px;color: black;background: white;">
    <!--1st-->
    <div id="first">
      <div class="page page-1">
        <h3>Test page 1</h3>
        <p>This is an page for testing 1, This is an page for testing 1, This is an page for testing 1, This is an page for testing 1</p>
      </div>
      <div class="page page-2">
        <h3>Test page 2</h3>
        <p>
          <img src="./content.jpg" crossOrigin="Anonymous" />
        </p>
      </div>
      <div class="page page-3">
        <h3>Test page 3</h3>
        <p>This is an page for testing 3</p>
      </div>
    </div>
    <!--2nd-->
    <div id="second">
      <div class="page page-4">
        <h3>Test page 4</h3>
        <p>This is an page for testing 3</p>
      </div>
      <div class="page page-5">
        <h3>Test page 5</h3>
        <p>
          This is an page for testing 5
          <p>
            <img src="./content.jpg" />
          </p>
        </p>
      </div>
    </div>
  </div>

  <script src="dist/jspdf-html2canvas.js"></script>
  <script>
  
  document.getElementById('print-btn').addEventListener('click', function() {
    // one page
    // html2PDF(document.getElementById('page'), {
    //   jsPDF: {
    //     format: 'b5',
    //   },
    //   imageType: 'image/png',
    //   margin: {
    //     top: 30,
    //     right: 10,
    //     bottom: 30,
    //     left: 10,
    //   },
      // watermark: {
      //   src: './test.png',
      //   ratio: 0.5
      // },
      // watermark(pdf) {
      //   pdf.setTextColor('#ddd');
      //   pdf.text(50, pdf.internal.pageSize.height - 30, 'Watermark');
      // },
    // })
    // multi page
    html2PDF([
      document.getElementById('first'),
      document.getElementById('second'),
    ], {
      jsPDF: {
        format: 'b5',
      },
      margin: {
        top: 30,
        right: 10,
        bottom: 30,
        left: 10,
      },
    })
  });
  </script>
</body>
</html>